<?php
class pegawai_model extends CI_Model{ 

	function pegawai_model()
	{
		parent::__construct();
	}
 
	/* GET DAT APEGAWAI */
		function getDataPegawai($id=''){
			$query=$this->db->query("select t_pegawai.id,t_pegawai.nik,t_pegawai.kd_cabang,t_pegawai.kd_unit_kerja,t_pegawai.kd_jabatan,t_pegawai.nama,t_pegawai.kd_level,m_jabatan.nama_jabatan,m_unit_kerja.nama_unit_kerja,m_cabang.nama_cabang from t_pegawai
		    LEFT JOIN m_jabatan ON t_pegawai.kd_jabatan=m_jabatan.kd_jabatan
            LEFT JOIN m_unit_kerja ON t_pegawai.kd_unit_kerja=m_unit_kerja.kd_unit_kerja
            LEFT JOIN m_cabang ON t_pegawai.kd_cabang=m_cabang.kd_cabang 
			where t_pegawai.id='$id'");
			return $query->row();
		}
		function getDataPegawaibyNik($id=''){
			$query=$this->db->query("select t_pegawai.id,t_pegawai.nik,t_pegawai.kd_cabang,t_pegawai.kd_unit_kerja,t_pegawai.kd_jabatan,t_pegawai.nama,t_pegawai.kd_level,m_jabatan.nama_jabatan,m_unit_kerja.nama_unit_kerja,m_cabang.nama_cabang from t_pegawai
		    LEFT JOIN m_jabatan ON t_pegawai.kd_jabatan=m_jabatan.kd_jabatan
            LEFT JOIN m_unit_kerja ON t_pegawai.kd_unit_kerja=m_unit_kerja.kd_unit_kerja
            LEFT JOIN m_cabang ON t_pegawai.kd_cabang=m_cabang.kd_cabang 
			where t_pegawai.id='$id'");
			return $query->row();
		}
		function getDataPegawaibyNikz($nik=''){
			$query=$this->db->query("select t_pegawai.id,t_pegawai.nik,t_pegawai.kd_cabang,t_pegawai.kd_unit_kerja,t_pegawai.kd_jabatan,t_pegawai.nama,t_pegawai.kd_level,m_jabatan.nama_jabatan,m_unit_kerja.nama_unit_kerja,m_cabang.nama_cabang from t_pegawai
		    LEFT JOIN m_jabatan ON t_pegawai.kd_jabatan=m_jabatan.kd_jabatan
            LEFT JOIN m_unit_kerja ON t_pegawai.kd_unit_kerja=m_unit_kerja.kd_unit_kerja
            LEFT JOIN m_cabang ON t_pegawai.kd_cabang=m_cabang.kd_cabang 
			where t_pegawai.nik='$nik'");
			return $query->row();
		}
	/* --- */
	function count_cuti($id=''){
		$jumlah='';
		$status=$this->session->userdata('STATUS');
		$addTag="";
		if($status!=0){
		$addTag="where t_cuti.nik='".$this->session->userdata('NIK')."'";	
		}		
		$query=$this->db->query("select count(1) as jumlah from t_cuti $addTag");
			 if ($query->num_rows() > 0) {
				foreach ($query->result() as $data) {
				$jumlah=$data->jumlah;
				}
				return $jumlah;
			}
	}
	 
	function detailPegawai($id=''){
		$table="<table class='table-bordered' style='width:100%'>";	
			$judul=$this->input->post('judul');
			$query=$this->db->query("select a.id,a.nik,a.nama,m_jabatan.nama_jabatan,m_unit_kerja.nama_unit_kerja,m_cabang.nama_cabang from t_pegawai a
		    LEFT JOIN m_jabatan ON a.kd_jabatan=m_jabatan.kd_jabatan
            LEFT JOIN m_unit_kerja ON a.kd_unit_kerja=m_unit_kerja.kd_unit_kerja
            LEFT JOIN m_cabang ON a.kd_cabang=m_cabang.kd_cabang 
			where a.id='$id'");
			 if ($query->num_rows() > 0) {
				foreach ($query->result() as $row) {
					$table.="<tr>";	
					$table.="<td colspan='3'><h3>Detail Pengambilan Cuti</h3></td>";	
					$table.="</tr>";
					$table.="<tr>";	
					$table.="<td style='width:150px'>Nik Pegawai</td><td><span class='label label-important'>".$row->nik."</span></td>";
					$table.="</tr>";
					$table.="<tr>";	
					$table.="<td>Nama Pegawai</td><td><span class='label label-important'>".$row->nama."</span></td>";
					$table.="</tr>";	
					$table.="<tr>";	
					$table.="<td>Sisa Cuti</td><td><span class='label label-important'>".$this->cuti_model->getSisaCuti($row->nik)."&nbsp Hari</span></td>";
					$table.="</tr>";	
				}
			}
			$table.="</table>";	
			echo $table;
	}
 
    function info($id=''){
	    $query=$this->db->query("select * from artikel where id='$id'");
		return $query->row();
    }
	function infobynik($nik=''){
	    $query=$this->db->query("select * from artikel where nik='$nik'");
		return $query->row();
    }
	function cekNik($nik=''){
	    $nik=$this->input->post('nik');
		$query=$this->db->query("select * from t_pegawai where nik='$nik'");
		$countNik=$query->num_rows();
		if($countNik!=0){
			echo "NIK ADA";
		}
	}
	 
}
// END RiskIssue_model Class

/* End of file RiskIssue_model.php */
/* Location: ./application/models/RiskIssue_model.php */
?>